from typing import List


class Solution:
    def threeSum(self, nums: List[int]) -> List[List[int]]:
        num2count = {}
        for i, n in enumerate(nums):
            if n in num2count:
                num2count[n].append(i)
            else:
                num2count[n] = [i]
        result = set()
        for i in range(len(nums)):
            for j in range(len(nums)):
                if i == j: continue
                s = nums[i] + nums[j]
                if -s in num2count:
                    for idx in num2count[-s]:
                        if idx != i and idx != j:
                            result.add(tuple(sorted([nums[i], nums[j], nums[idx]])))
        return list(result)